package com.lxj.service.impl;

import com.lxj.domain.Group;
import com.lxj.mapper.GroupMapper;
import com.lxj.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GroupServiceImpl implements GroupService {
    @Autowired
    private GroupMapper groupMapper;
    @Override
    public List<Group> selectAll(Group group) {
        return groupMapper.selectAll(group);
    }

    @Override
    public int getNUmber() {
        return groupMapper.getNumber();
    }

    @Override
    @Transactional
    public int delete(Integer[] id) {
        clearUserGroup(id);
        clearMember(id);
        return groupMapper.delete(id);
    }
    @Override
    public void clearUserGroup(Integer[] id){
        groupMapper.clearUserGroup(id);
    }

    @Override
    public void clearMember(Integer[] id) {
        groupMapper.clearMember(id);
    }

    @Override
    public int add(Group group) {
        return groupMapper.add(group);
    }

    @Override
    public Group findById(Integer id) {
        return groupMapper.findById(id);
    }

    @Override
    @Transactional
    public int edit(Group group) {
        editUserGroup(group);
        editMemberGroup(group);
        return groupMapper.edit(group);
    }

    @Override
    public void editUserGroup(Group group) {
        groupMapper.editUserGroup(group);
    }

    @Override
    public void editMemberGroup(Group group) {
        groupMapper.editMemberGroup(group);
    }

    @Override
    public Group getConfirm(Group group) {
        return groupMapper.getConfirm(group);
    }
}
